import com.google.auto.service.AutoService;
import com.ysb.deors.annotations.Complexity;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import java.util.Set;


@AutoService(Processor.class)
@SupportedAnnotationTypes({"com.ysb.deors.annotations.Complexity"})
@SupportedSourceVersion(SourceVersion.RELEASE_8)
// javac -Aoption1=value1 -Aoption2=value2 MyFile.java
@SupportedOptions({"-option1", "-option2"})
public class ComplexityProcessor extends AbstractProcessor {
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    // 获取传递给注解处理器的选项
    String option1 = processingEnv.getOptions().get("-option1");
    String option2 = processingEnv.getOptions().get("-option2");

    // 打印选项值
    System.out.println("Option 1: " + option1);
    System.out.println("Option 2: " + option2);

    for (Element elem : roundEnv.getElementsAnnotatedWith(Complexity.class)) {
      Complexity complexity = elem.getAnnotation(Complexity.class);
      String message = "annotation found in " + elem.getSimpleName()
        + " with complexity " + complexity.value();
      processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message);
    }
    return true; // no further processing of this annotation type
  }
}